package com.uit.project.bustrip.adapter;

import java.util.ArrayList;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.uit.project.bustrip.R;
import com.uit.project.bustrip.entity.User;

public class UserListAdapter extends ArrayAdapter<User> {
	private ArrayList<User> items;
	private Activity context;
	
	public UserListAdapter(Activity context, ArrayList<User> items) {
		super(context, R.layout.activity_user_list_item, items);
		this.items = items;
		this.context = context;
	}
	static class ViewHolder {
		protected TextView name;
		protected TextView phone;
		protected TextView email;
	}
	/* (non-Javadoc)
	 * @see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final User item = items.get(position);
		View v = null;
		if (convertView == null) {
			LayoutInflater inflater = context.getLayoutInflater();
			v = inflater.inflate(R.layout.activity_user_list_item, null);
			final ViewHolder vh = new ViewHolder();
			vh.name = (TextView) v.findViewById(R.id.name);
			vh.phone = (TextView) v.findViewById(R.id.phone);
			vh.email = (TextView) v.findViewById(R.id.email);
			v.setTag(vh);
		}
		else{
			v = convertView;
		}
		ViewHolder holder = (ViewHolder) v.getTag();
		holder.name.setText(item.username);
		holder.phone.setText(item.numberphone);
		holder.email.setText(item.email);
		return v;
	}
	
}
